import Vue from 'vue'
import App from './App.vue'
import router from './router/index.js'
import initStore from "@/store/index.js"
import Axios from  "axios"
import api from "./api"
import VueAwesomeSwiper from "vue-awesome-swiper"
import "swiper/dist/css/swiper.css"
import './registerServiceWorker'
import "./assets/icon-font/font_d99ctjkonjl/iconfont.css"
const store = initStore();


Vue.use(VueAwesomeSwiper)
Vue.prototype.$api = api;
Vue.prototype.$axios  = Axios;
Vue.config.productionTip = false


// 全局前置守卫
router.beforeEach((to, from, next) => {
  // 判断页面进入之前是否需要登陆
  if (to.matched.some((item) => item.meta.isLogin)) {
    // 需要登陆
    // 定义一个token
    // let token = true
    let token = localStorage.getItem("token");
    // 存入到vuex
    store.dispatch("setTokenAction",token);
    // 是否已经登陆
    if(token){
      next();
    }else{
      next({
        path:"/login"
      })
    }
  }else{
    // 不需要登陆
    next();
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')


